/**  
 * All rights Reserved, Designed By www.beonelot.com
 * @Package: com.bccah.modlib.dbdo.service.impl
 * @Filename: AcsControlBlockInfoServiceImpl.java
 * @Description: TODO(AcsControlBlockInfoService接口实现)
 * @author: 金鑫智慧
 * @date: 2020-04-03
 * @version: V1.0
 * @Copyright: 2018 www.beonelot.com Inc. All rights reserved.
 * 注意：本内容仅限于重庆金鑫智慧科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
package com.jinxin.platform.cdfaceacs.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinxin.platform.cdfaceacs.mapper.JurenAcsControlSysParamMapper;
import com.jinxin.platform.cdfaceacs.pojo.domains.AcsControlSysParamDO;
import com.jinxin.platform.cdfaceacs.service.AcsControlSysParamService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO(AcsControlBlockInfoService接口实现)
 * @Classn: AcsControlBlockInfoServiceImpl
 * @author SY
 * @date 2020-04-03
 */
@Service
public class AcsControlSysParamServiceImpl implements AcsControlSysParamService {

    @Resource
    JurenAcsControlSysParamMapper sysParamMapper;

    @Override
    public PageInfo<AcsControlSysParamDO> selParamPage(int page, int size) {
        PageHelper.startPage(page,size);//这行是重点，表示从pageNum页开始，每页pageSize条数据
        List<AcsControlSysParamDO> list = sysParamMapper.selectAll();
        PageInfo<AcsControlSysParamDO> pageInfo = new PageInfo<AcsControlSysParamDO>(list);
        return pageInfo;
    }

    @Override
    public int saveParam(AcsControlSysParamDO paramDO) {
        return sysParamMapper.insert(paramDO);
    }

    @Override
    public int updateParam(AcsControlSysParamDO paramDO) {
        return sysParamMapper.updateByPrimaryKeySelective(paramDO);
    }

    @Override
    public int delParam(String pid) {
        return sysParamMapper.deleteByPrimaryKey(pid);
    }

    @Override
    public List<AcsControlSysParamDO> selParamByInfo(AcsControlSysParamDO paramDO) {
        return sysParamMapper.selParamByInfo(paramDO );
    }

    @Override
    public AcsControlSysParamDO selectByPrimaryKey(String acsSysParamId) {
        return sysParamMapper.selectByPrimaryKey(acsSysParamId);
    }

    @Override
    public Map selFtpInfo() {
        Map<String,String> resMap = new HashMap<>();
        AcsControlSysParamDO paramDO = new AcsControlSysParamDO();
        paramDO.setParamKey("ftp.host");
        List<AcsControlSysParamDO> paramDOList = this.selParamByInfo(paramDO );
        if(paramDOList == null || paramDOList.size()==0 ){
            resMap.put("res","false" );
            resMap.put("msg","未配置ftp.host参数");
            return resMap;
        }else{
            resMap.put("host", paramDOList.get(0).getParamVal() );
        }
        paramDO.setParamKey("ftp.user");
        paramDOList = this.selParamByInfo(paramDO );
        if(paramDOList == null || paramDOList.size()==0 ){
            resMap.put("res","false" );
            resMap.put("msg","未配置ftp.user");
            return resMap;
        }else{
            resMap.put("ftpUser", paramDOList.get(0).getParamVal() );
        }
        paramDO.setParamKey("ftp.password");
        paramDOList = this.selParamByInfo(paramDO );
        if(paramDOList == null || paramDOList.size()==0 ){
            resMap.put("res","false" );
            resMap.put("msg","未配置ftp.password");
            return resMap;
        }else{
            resMap.put("ftpPwd", paramDOList.get(0).getParamVal() );
        }
        resMap.put("res","true" );
        return resMap;
    }


}
